home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / Permissions.h < prev    next >
C/C++ Source or Header  |  2011-11-06  |  7KB  |  191 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 2002-2004 - Tim Kosse <tim.kosse@gmx.de>
  4.  
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. // Permissions.h: Schnittstelle fⁿr die Klasse CPermissions.
  20. //
  21. //////////////////////////////////////////////////////////////////////
  22.  
  23. #if !defined(AFX_PERMISSIONS_H__33DEA50E_AA34_4190_9ACD_355BF3D72FE0__INCLUDED_)
  24. #define AFX_PERMISSIONS_H__33DEA50E_AA34_4190_9ACD_355BF3D72FE0__INCLUDED_
  25.  
  26. #if _MSC_VER > 1000
  27. #pragma once
  28. #endif // _MSC_VER > 1000
  29.  
  30. #include "Accounts.h"
  31.  
  32. #define FOP_READ        0x01
  33. #define FOP_WRITE        0x02
  34. #define FOP_DELETE        0x04
  35. #define FOP_APPEND        0x08
  36. #define FOP_CREATENEW    0x10
  37. #define DOP_DELETE        0x20
  38. #define DOP_CREATE        0x40
  39. #define FOP_LIST        0x80
  40.  
  41. #define PERMISSION_DENIED            0x01
  42. #define PERMISSION_NOTFOUND            0x02
  43. #define PERMISSION_DIRNOTFILE        (0x04 | PERMISSION_DOESALREADYEXIST)
  44. #define PERMISSION_FILENOTDIR        (0x08 | PERMISSION_DOESALREADYEXIST)
  45. #define PERMISSION_DOESALREADYEXIST    0x10
  46. #define PERMISSION_INVALIDNAME        0x20
  47.  
  48. class TiXmlElement;
  49. class CPermissionsHelperWindow;
  50. class COptions;
  51.  
  52. class CUser : public t_user
  53. {
  54. public:
  55.     CStdString homedir;
  56.  
  57.     // Replace :u and :g (if a group it exists)
  58.     void DoReplacements(CStdString& path) const;
  59.  
  60.     /*
  61.      * t_alias is used in the alias maps.
  62.      * See implementation of PrepareAliasMap for a detailed
  63.      * description
  64.      */
  65.     struct t_alias
  66.     {
  67.         CStdString targetFolder;
  68.         CStdString name;
  69.     };
  70.  
  71.     void PrepareAliasMap();
  72.  
  73.     // GetAliasTarget returns the target of the alias with the specified
  74.     // path and name or returns an empty string if the alias can't be found.
  75.     CStdString GetAliasTarget(const CStdString& path, const CStdString& virtualPath, const CStdString& name) const;
  76.  
  77.     std::multimap<CStdString, t_alias> aliasMap;
  78.     std::map<CStdString, CStdString> virtualAliases;
  79.     std::multimap<CStdString, CStdString> virtualAliasNames;
  80. };
  81.  
  82. struct t_dirlisting
  83. {
  84.     char buffer[8192];
  85.     unsigned int len;
  86.  
  87.     t_dirlisting *pNext;
  88. };
  89.  
  90. enum _facts {
  91.     fact_type,
  92.     fact_size,
  93.     fact_modify,
  94.     fact_perm
  95. };
  96.  
  97. class CPermissions  
  98. {
  99. public:
  100.     CPermissions();
  101.     virtual ~CPermissions();
  102.  
  103. protected:
  104.     /*
  105.      * CanonifyPath takes the current and the new server dir as parameter,
  106.      * concats the paths if neccessary and canonifies the dir:
  107.      * - remove dot-segments
  108.      * - convert backslashes into slashes
  109.      * - remove double slashes
  110.      */
  111.     CStdString CanonifyServerDir(CStdString currentDir, CStdString newDir) const;
  112.  
  113. public:
  114.     // Change current directory to the specified directory. Used by CWD and CDUP
  115.     int ChangeCurrentDir(LPCTSTR username, CStdString& currentdir, CStdString &dir);
  116.  
  117.     // Retrieve a directory listing. Pass the actual formatting function as last parameter.
  118.     int GetDirectoryListing(LPCTSTR username, CStdString currentDir, CStdString dirToDisplay,
  119.                              t_dirlisting *&pResult, CStdString& physicalDir, 
  120.                              CStdString& logicalDir,
  121.                              void (*addFunc)(t_dirlisting *&pResult, bool isDir, const char* name, const t_directory& directory, __int64 size, FILETIME* pTime, const char* dirToDisplay, bool *enabledFacts),
  122.                              bool useUTF8, bool *enabledFacts = 0);
  123.  
  124.     char* ConvertFilename(const CStdString& filename, bool useUTF8);
  125.  
  126.     // Full direcoty listing with all details. Used by LIST command
  127.     static void AddLongListingEntry(t_dirlisting *&pResult, bool isDir, const char* name, const t_directory& directory, __int64 size, FILETIME* pTime, const char* dirToDisplay, bool *);
  128.  
  129.     // Directory listing with just the filenames. Used by NLST command
  130.     static void AddShortListingEntry(t_dirlisting *&pResult, bool isDir, const char* name, const t_directory& directory, __int64 size, FILETIME* pTime, const char* dirToDisplay, bool *);
  131.  
  132.     // Directory listing format used by MLSD
  133.     static void AddFactsListingEntry(t_dirlisting *&pResult, bool isDir, const char* name, const t_directory& directory, __int64 size, FILETIME* pTime, const char* dirToDisplay, bool *enabledFacts);
  134.  
  135.     CStdString GetHomeDir(LPCTSTR username, bool physicalPath = false) const;
  136.     CStdString GetHomeDir(const CUser &user, bool physicalPath = false) const;
  137.  
  138.     int CheckDirectoryPermissions(LPCTSTR username, CStdString dirname, CStdString currentdir, int op, CStdString &physicalDir, CStdString &logicalDir);
  139.     int CheckFilePermissions(LPCTSTR username, CStdString filename, CStdString currentdir, int op, CStdString &physicalDir, CStdString &logicalDir);
  140.  
  141.     BOOL GetUser(CStdString username, CUser &userdata) const;
  142.     BOOL CheckUserLogin(LPCTSTR username, LPCTSTR pass, CUser &userdata, BOOL noPasswordCheck = FALSE);
  143.  
  144.     BOOL GetAsCommand(char **pBuffer, DWORD *nBufferLength);
  145.     BOOL ParseUsersCommand(unsigned char *pData, DWORD dwDataLength);
  146.     void AutoCreateDirs(LPCTSTR username);
  147.     void ReloadConfig();
  148.  
  149.     int GetFact(LPCTSTR username, CStdString currentDir, CStdString file, CStdString& fact, CStdString& logicalName, bool enabledFacts[3]);
  150.  
  151.     static void DestroyDirlisting(struct t_dirlisting* pListing);
  152.  
  153. protected:
  154.     bool Init();
  155.     void UpdateInstances();
  156.  
  157.     void ReadSettings();
  158.  
  159.     void ReadPermissions(TiXmlElement *pXML, t_group &user, BOOL &bGotHome);
  160.     void SavePermissions(TiXmlElement *pXML, const t_group &user);
  161.  
  162.     void ReadSpeedLimits(TiXmlElement *pXML, t_group &group);
  163.     void SaveSpeedLimits(TiXmlElement *pXML, const t_group &group);
  164.  
  165.     void ReadIpFilter(TiXmlElement *pXML, t_group &group);
  166.     void SaveIpFilter(TiXmlElement *pXML, const t_group &group);
  167.  
  168.     void SetKey(TiXmlElement *pXML, LPCTSTR name, LPCTSTR value);
  169.     void SetKey(TiXmlElement *pXML, LPCTSTR name, int value);
  170.     
  171.     int GetRealDirectory(CStdString directory, const CUser &user, t_directory &ret, BOOL &truematch);
  172.  
  173.     static CCriticalSectionWrapper m_sync;
  174.  
  175.     bool WildcardMatch(CStdString string, CStdString pattern) const;
  176.     
  177.     typedef std::vector<CUser> t_UsersList; 
  178.     typedef std::vector<t_group> t_GroupsList; 
  179.     static t_UsersList m_sUsersList;
  180.     static t_GroupsList m_sGroupsList;
  181.     t_UsersList m_UsersList;
  182.     t_GroupsList m_GroupsList;
  183.     
  184.     static std::list<CPermissions *> m_sInstanceList;
  185.     CPermissionsHelperWindow *m_pPermissionsHelperWindow;
  186.  
  187.     friend CPermissionsHelperWindow;
  188. };
  189.  
  190. #endif // !defined(AFX_PERMISSIONS_H__33DEA50E_AA34_4190_9ACD_355BF3D72FE0__INCLUDED_)
  191.